home *** CD-ROM | disk | FTP | other *** search
/ stazsoftware.com / www.stazsoftware.com.tar / www.stazsoftware.com / futurebasic / sample-code / helpProj.sit / Help Project Folder / HTML Cal.INCL < prev    next >
Text File  |  2005-04-15  |  12KB  |  485 lines

  1.  
  2. '~'2
  3. '~'2
  4. '     MAKE HTML CALENDAR Include
  5. '
  6. '
  7. '~'2
  8.  
  9. toolbox fn HRDrawInPort(HRReference  hrRef,RgnHandle updateRgnH,CGrafPtr grafPtr) = OSStatus
  10. toolbox fn HRNewReferenceInWindow(HRReference * hrRef,OSType rendererType,WindowRef inWindowRef)= OSStatus
  11. toolbox fn HRSetWindowRef(HRReference hrRef,WindowRef windowRef) = OSStatus
  12. toolbox fn CopyWindowTitleAsCFString( WindowRef inWindow,CFStringRef * outString ) = OSStatus
  13.  
  14. begin globals
  15.  
  16. dim gTopic$
  17. dim @gHRref as  HRReference// heavily used HR reference
  18. dim @gPort as ^CGrafPort' as ptr// "@" means don't use register
  19. dim @grenderRect as rect
  20. dim gPrefFolderVol
  21.  
  22. END GLOBALS
  23.  
  24. GOTO "EndOfHTMLCAL"
  25.  
  26.  
  27. CLEAR LOCAL
  28. DIM pbBlk.128,Filename$,Index%,OSErr%,num,loop
  29. DIM resHndl&
  30. '~'2
  31. LOCAL FN BuildHelpTopicList
  32. '~'2
  33. USERESFILE(gResRef)
  34. num = FN countStr(_HelpListSTR)
  35. FOR loop = num to 1 step -1
  36. FN delElement(loop,_HelpListSTR)
  37. next
  38. gPrefFolderVol = FOLDER ("Help",SYSTEM(_aplvol))
  39. Index% = 1
  40. DO
  41. pbBlk.ioFDirIndex%  = Index%
  42. pbBlk.ioNamePtr&    = @Filename$
  43. pbBlk.ioVRefNum%    = gPrefFolderVol
  44. pbBlk.ioDirID&      = 0
  45. #IF CarbonLib = 0
  46. OSErr% = FN PBGetFInfoSync (pbBlk)
  47. #ELSE
  48. FN FBWDtoPBWD(pbBlk)
  49. OSErr% = FN PBHGetFInfoSync (pbBlk)
  50. #ENDIF
  51. gFileType&          = pbBlk.ioBuffer&
  52. LONG IF OSErr% = _noErr
  53. LONG IF gFileType& = _"TEXT"' or gFileType& = _""
  54. FN apndElement(_HelpListSTR,Filename$)
  55. END IF
  56. END IF
  57. INC (Index%)
  58. UNTIL OSErr% <> _noErr
  59. updateresfile(system(_aplres))
  60. FN InitHelpTopicList
  61. END FN
  62.  
  63.  
  64. Clear Local Mode
  65. Dim err As OSErr
  66. Dim pb  As CInfoPBRec
  67. '~'2
  68. Local Fn FBWDToFSSpec( @namePtr As .Str63,vRefNum As Int, fSpec As .FSSpec )
  69. '~'2
  70. pb.ioNamePtr = namePtr
  71. pb.ioVRefNum = vRefNum
  72. #If CarbonLib
  73. Fn FBWDToPBWD( pb )
  74. #Endif
  75. err = Fn PBGetCatInfoSync( pb )
  76. If err != _noErr Then Exit Fn
  77. fSpec.name    =  namePtr.nil$
  78. fSpec.vRefNum =  pb.ioVRefNum
  79. fSpec.parID   =  pb.ioFlParID
  80. End Fn = err
  81.  
  82.  
  83. local
  84. dim err
  85. '~'2
  86. local fn setHTMLrect
  87. '~'2
  88. getport(gPort)
  89. grenderRect  = @gPort.portRect%
  90. call OffsetRect(grenderRect,1,0)
  91. call InsetRect(grenderRect,0,-1)
  92. LONG IF window(_outputwnd) = _MyCalendarHelp2Wnd
  93. FN pGgetObj(_MyCalendarHelp2Wnd,_HelpTopicList)
  94. grenderRect.right% = WINDOW(_width)-2
  95. grenderRect.bottom = gObjB'WINDOW(_height)-2
  96. grenderRect.left% = gObjR + 16'right side of list plus scroll button
  97. grenderRect.top% = gObjT'grenderRect.top% + 57
  98. END IF
  99. err = FN HRSetRenderingRect(gHRref,grenderRect)
  100. END FN
  101.  
  102.  
  103. clear local
  104. dim err,spec as fsspec
  105. dim rgn   as rgnHandle
  106. '~'2
  107. local fn HTMLGotoFile(HRref as long,HTMLName$,HTMLVol%)
  108. '~'2
  109. fn FBmakefsspec(HTMLVol%,0,HTMLName$,spec)
  110. err = fn HRGoToFile(HRref,#spec,_false,_zTrue)
  111. rgn = fn NewRgn
  112. long if rgn
  113. RectRgn(rgn,@grenderRect)
  114. err = fn HRdraw(gHRref,rgn)
  115. DisposeRgn( rgn )
  116. end if
  117. end fn 
  118.  
  119.  
  120. clear local
  121. dim err
  122. '~'2
  123. local fn HTMLBegin
  124. '~'2
  125. getport(gPort)
  126. err = fn HRNewReference(@gHRref,_kHRRendererHTML32Type,gPort)
  127. err = fn HRForceQuickdraw(gHRref,_false)'force quick draw drawing for this port due to some printers
  128. err = fn HRSetdrawborder(gHRref,_zTrue)
  129. err = FN HRSetScrollbarState(gHRref,2,2)
  130. fn setHTMLrect
  131. err = fn HRactivate(gHRref)
  132. end fn = gHRref
  133.  
  134.  
  135. local
  136. dim spec as fsspec
  137. dim err,wTitle$,outputwnd
  138. dim @wptr&
  139. dim rgn   as rgnHandle
  140. '~'2
  141. local fn showLocalURL(theURL$,vRef%)
  142. '~'2
  143. wTitle$ = theURL$
  144. outputwnd = WINDOW(_outputWnd)
  145. call GetPort(gPort)
  146. long if fn HRHTMLRenderingLibAvailable
  147. err = fn HRDeactivate(gHRref)
  148. err = fn HRDisposeReference(gHRref)
  149. err = fn HRNewReference(@gHRref,_kHRRendererHTML32Type,gPort)
  150. fn setHTMLrect
  151. Long If Fn FBWDToFSSpec(theURL$, vRef%, spec ) = _noErr
  152. long if fn HRGoToFile(gHRref,#spec,_false,_zTrue) = _noErr
  153. rgn = fn NewRgn
  154. long if( rgn )
  155. RectRgn( rgn,grenderRect)
  156. err = fn HRdraw(gHRref,rgn)
  157. DisposeRgn( rgn )
  158. end if
  159. end if
  160. end if
  161. end if
  162. WINDOW OUTPUT(outputwnd)
  163. end fn
  164.  
  165.  
  166. CLEAR LOCAL
  167. DIM helpVRef,err
  168. '~'2
  169. LOCAL FN BuildHelpWindow
  170. '~'2
  171. LONG IF WINDOW(-_MyCalendarHelp2Wnd)
  172. WINDOW _MyCalendarHelp2Wnd
  173. exit fn
  174. END IF
  175. LONG IF fn HRHTMLRenderingLibAvailable
  176. if gHRref then err = fn HRDeactivate(gHRref)
  177. if gHRref then err = fn HRDisposeReference(gHRref)
  178. gHRref = 0
  179. FN BuildHelpTopicList
  180. FN pGbuild(_MyCalendarHelp2Wnd)
  181. FN DrawList(HelpList)
  182. getport(gPort)
  183. fn HTMLBegin
  184. helpVRef = folder("Help",SYSTEM(_aplvol))
  185. err = fn HRForceQuickdraw(gHRref,_false)'force quick draw drawing for this port due to some printers
  186. fn HTMLGotoFile(gHRref,gTopic$,helpVRef)
  187. err = fn HRactivate(gHRref)
  188. xelse
  189. CALL paramtext("HTML Rendering is not available on this computer. Help cannot be displayed without that carbon library!","","","")
  190. FN pGshowErr(0)
  191. end if
  192. END FN
  193.  
  194.  
  195. LOCAL mode
  196. dim err,n,tvert,PageHt
  197. dim freMem&    as Sint32
  198. dim @mp,mp2    as point
  199. DIM renderrect as rect
  200. dim spec       as fsspec
  201. dim @Port      as ^CGrafPort
  202. dim @gPort     as ^CGrafPort
  203. dim rgn        as rgnHandle
  204. dim @HrRef     as HRReference
  205. DIM pRecH&
  206. '~'2
  207. LOCAL FN PrintHtml(FileName$,helpVRef)
  208. '~'2
  209. 'A lot more error testing can be done but adding simple beeps shows no problems with the toolbox calls
  210. getport(gPort)'get the port data
  211. err = fn FBmakefsspec(helpVRef,0,FileName$,spec)'make a file spec for the file in the folder passed in helpVRef
  212. pRecH& = PRHANDLE
  213. renderRect;8 = @PRecH&..prinfo.rPage.top%
  214.  
  215. 'InsetRect(renderRect,3,3)'inset the area 3 pixels for more margin
  216. renderRect.left = 72
  217. renderRect.top = 20
  218. renderRect.bottom = renderRect.bottom - 20
  219. renderRect.right = renderRect.right - 20
  220. PageHt = renderRect.bottom'calculate the page height
  221. tvert = 0'grenderRect.bottom'this is where the bottom starts for the first page
  222. err = fn HRNewReference(@HRref,_kHRRendererHTML32Type,gPort)'create a new HR reference
  223. err = fn HRForceQuickdraw(HRref,_true)'force quick draw drawing for this port due to some printers
  224. err = fn HRSetdrawborder(HRref,_false)'turn off drawing borders
  225. err = FN HRSetScrollbarState(HRref,1,1)'we dont want scroll bars
  226. err = FN HRSetRenderingRect(HRref,@renderRect)'set the html render rectangle to this size
  227. err = fn HRGoToFile(HRref,#spec,_false,_false)'go to the file but no history and no forced refresh
  228. err = FN HRGetRenderedImageSize(HRref,@mp)'now calculate the MAXIMUM verticle size needed to render this file
  229. mp2.h% = 0'mp2 is a point tracking the bottom left corner of the rendering
  230.  
  231. while tvert <= mp.v%'as long as the total verticle is less than the total needed
  232. 'n needs to be refined to determine offset of last line
  233. if tvert = 0 then n = 0 else n = 10'if this is the first page no scroll is needed
  234. mp2.v% = tvert - n'otherwise calculate the total verticle scroll
  235. err = FN HRScrollToLocation (HRref,@mp2)'set the scroll bar to the bottom of the previous page minus the offset
  236. rgn = fn NewRgn'create a new empty region
  237. long if rgn
  238. RectRgn(rgn,@renderRect)'create a region from the rendering rectangle 
  239. Route _toPrinter'tell the system to route to the printer
  240. getport(Port)'determine the printer port
  241. err = fn HRDrawInPort(HRref,rgn,Port)'draw the reference using the region and printer port
  242. DisposeRgn(rgn)'dispose of the region
  243. clear lprint'clear the lprint for this page
  244. end if
  245. tvert = tvert + PageHt'add a page height to the total verticle
  246. wend
  247. err = fn HRDisposeReference(HRref)'dispose of global ref
  248. close lprint'immediately close the printing
  249. route _toscreen'route back to screen
  250. END FN
  251.  
  252.  
  253.  
  254. CLEAR LOCAL
  255. DIM TheResponse,loop,NumTopics,helpVRef,err
  256. DIM as EventRecord evnt
  257. dim spec as fsspec
  258. dim @FromPage as UInt32
  259. Dim @ToPage as UInt32
  260. dim @w as WindowRef
  261. dim as CFStringRef  @DocTitle
  262. dim temp$
  263. dim @orientation as UInt16
  264. '~'2
  265. LOCAL FN CallPrintRoutine
  266. '~'2
  267. TheResponse = FN ALERT(2222,0)
  268. IF TheResponse = 1 THEN EXIT FN
  269. NumTopics = FN countStr(_HelpListSTR)
  270. DEF PAGE
  271. err = fn PMSetFirstPage(gFBPrintSettings,1, _false) ' dunno why it is _false / maybe _true works too
  272. err = fn PMSetLastPage (gFBPrintSettings ,NumTopics, _false)
  273. err = fn PMSetPageRange(gFBPrintSettings,1,NumTopics)
  274. err = fn PMGetOrientation(gFBPageFormat,@orientation)
  275. LONG IF NOT PRCANCEL
  276. DEF LPRINT
  277. err = Fn PMGetFirstPage(gFBPrintSettings,FromPage)
  278. err = Fn PMGetLastPage (gFBPrintSettings,ToPage )
  279. LONG IF NOT PRCANCEL
  280. helpVRef = folder("Help",SYSTEM(_aplvol))'get the folder location for the file to be used
  281. LONG IF FromPage <> 0 and FromPage <= ToPage and ToPage <> 0 and FromPage <= NumTopics and ToPage <= NumTopics
  282. WINDOW(_MyCalendarHelp2Wnd)
  283. for loop = FromPage to ToPage
  284. gTopic$ = STR#(_HelpListSTR,loop)
  285. WINDOW(_MyCalendarHelp2Wnd)
  286. fn FBBeginSession
  287. DocTitle = fn CFStringCreateWithPascalString(0,gTopic$,_kCFStringEncodingASCII)
  288. err = fn PMSetJobNameCFString(gFBPrintSettings, DocTitle)
  289. err = fn PMSetOrientation (gFBPageFormat,orientation,_false)
  290. FN PrintHtml(gTopic$,helpVRef)
  291. CFRelease(DocTitle)
  292. next
  293. fn pGClose(_MyCalendarHelp2Wnd)
  294. gTopic$ = STR#(_HelpListSTR,1)
  295. FN BuildHelpWindow
  296. XELSE
  297. TheResponse = FN ALERT(2223,0)
  298. END IF
  299. END IF
  300. END IF
  301. END FN
  302.  
  303.  
  304. clear local
  305. dim loop,gerr,helpVref
  306. '~'1
  307. local fn SizeHelpWnd
  308. '~'1
  309. FOR loop = 1 to 2
  310. FN pGgetObj(_MyCalendarHelp2Wnd,loop)
  311. gObjSel = loop
  312. gObjB = WINDOW(_height)- 6
  313. FN pGputObj(_MyCalendarHelp2Wnd,loop)
  314. NEXT
  315. updateresfile(gResRef)
  316. loop = HelpList.newselect
  317. FN InitHelpTopicList
  318. HelpList.newselect = loop
  319. fn PGDRAWCONTROLS
  320.  
  321.  
  322. gerr = fn HRDeactivate(gHRref)
  323. gerr = fn HRDisposeReference(gHRref)
  324. gHRref = 0
  325. fn HTMLBegin
  326. fn setHTMLrect
  327. helpVRef = folder("Help",SYSTEM(_aplvol))
  328. gerr = fn HRForceQuickdraw(gHRref,_false)'force quick draw drawing for this port due to some printers
  329. fn HTMLGotoFile(gHRref,gTopic$,helpVRef)
  330. gerr = fn HRactivate(gHRref)
  331. HRScreenConfigurationChanged
  332. end fn
  333.  
  334.  
  335.  
  336. clear local
  337. dim gerr,newx
  338. DIM as EventRecord evnt
  339. '~'1
  340. local fn ResizeListArea
  341. '~'1
  342. gObjSelB = WINDOW(_height)-4
  343. WHILE FN BUTTON
  344. getmouse(gMouseY)
  345. long if gMouseX > 90 and gMouseX < 400
  346. setrect(gObjSelT,gMouseX - 8,gObjSelT,gMouseX + 8,WINDOW(_height)-4)
  347. gerr = FN EventAvail(0,evnt)'allows time for system tasks and stop the spinning cursor in OSX
  348. newx = gObjSelL
  349. END IF
  350. WEND
  351. FN pGgetObj(_MyCalendarHelp2Wnd,1)
  352. gObjR = newx
  353. FN pGputObj(_MyCalendarHelp2Wnd,1)
  354.  
  355. FN pGgetObj(_MyCalendarHelp2Wnd,2)
  356. gObjL = newx + 16
  357. gObjSelL = gObjL
  358. FN pGputObj(_MyCalendarHelp2Wnd,2)
  359.  
  360. FN pGgetObj(_MyCalendarHelp2Wnd,_SizeTheListObj)
  361. gObjL = newx
  362. gObjR = gObjL + 16
  363. gObjSelL = gObjL
  364. gObjSelR = gObjR
  365. FN pGputObj(_MyCalendarHelp2Wnd,_SizeTheListObj)
  366.  
  367. updateresfile(gresRef)
  368. fn SizeHelpWnd
  369. end fn
  370.  
  371.  
  372. /*begin record EventRecord
  373. dim what          as short
  374. dim message       as UInt32
  375. dim when          as UInt32
  376. dim where         as point
  377. dim modifiers     as short
  378. end record*/
  379.  
  380.  
  381. "EndOfHTMLCAL"
  382. DIM helpVRef,gerr
  383.  
  384. dim rgn  as rgnHandle
  385. '~':
  386. '~':
  387. LONG IF window(_outputwnd) = _MyCalendarHelp2Wnd
  388. long if gHRref 
  389. long if FN HRIsHREvent(event)
  390. call FlushEvents(_everyEvent, 0 )
  391. % event,0
  392. gLongAction& = 0
  393. end if
  394. end if
  395. end if
  396. '~':
  397. '~':
  398.  
  399. SELECT gLongAction&
  400.  
  401. 'CASE _btnLong
  402. CASE _oUserClick
  403. long if gObjUserTp& = _"szee"
  404. FN ResizeListArea
  405. END IF
  406.  
  407. LONG IF gObjUserTp& = _"MICN" and gWhichClass = _MyCalendarHelp2Wnd
  408. SELECT gWhichObjElem
  409. CASE 4
  410. HelpList.newselect = 1
  411. gerr = fn HRDeactivate(gHRref)
  412. gerr = fn HRDisposeReference(gHRref)
  413. gHRref = 0
  414. fn HTMLBegin
  415. helpVRef = folder("Help",SYSTEM(_aplvol))
  416. gTopic$ = "1 Introduction"
  417. gerr = fn HRForceQuickdraw(gHRref,_false)'force quick draw drawing for this port due to some printers
  418. fn HTMLGotoFile(gHRref,gTopic$,helpVRef)
  419. gerr = fn HRactivate(gHRref)
  420. CASE 5
  421. FN CallPrintRoutine
  422. CASE 6
  423. fn pGClose(_MyCalendarHelp2Wnd)
  424. gKissofDeath = _true
  425. END SELECT
  426. END IF
  427.  
  428. LONG IF gObjUserTp& = _"List"
  429. LONG IF WINDOW(_outputWnd) = _MyCalendarHelp2Wnd
  430. gTopic$ = FN DoListSelecton$(HelpList)
  431. gerr = fn HRDeactivate(gHRref)
  432. gerr = fn HRDisposeReference(gHRref)
  433. gHRref = 0
  434. fn HTMLBegin
  435. helpVRef = folder("Help",SYSTEM(_aplvol))
  436. fn HTMLGotoFile(gHRref,gTopic$,helpVRef)
  437. gerr = fn HRactivate(gHRref)
  438. setrect(gObjT,0,0,400,60)
  439. fn invalrect(gObjT)
  440. END IF
  441. END IF
  442.  
  443. CASE _wClose
  444. LONG IF gWhichClass = _MyCalendarHelp2Wnd
  445. long if gHRref
  446. gerr = fn HRDeactivate(gHRref)
  447. gerr = fn HRDisposeReference(gHRref)
  448. gHRref = 0
  449. END IF
  450. END IF
  451.  
  452.  
  453. case _wUpdate',_wClicked
  454. select gWhichClass
  455.  
  456. case _MyCalendarHelp2Wnd
  457. rgn = fn NewRgn
  458. long if(rgn)
  459. fn setHTMLrect
  460. gerr = fn HRactivate(gHRref)
  461. gerr = FN HRSetRenderingRect(gHRref,grenderRect)
  462. RectRgn(rgn,grenderRect)
  463. gerr = fn HRdraw(gHRref,rgn)
  464. DisposeRgn(rgn)
  465. gerr = fn hractivate(gHRref)
  466. flushwindowbuffer
  467. fn validrect(gBigT)
  468. end if
  469. end select
  470.  
  471. CASE _wSized',_wUpdate,_wClicked
  472. select gWhichClass
  473.  
  474. case _MyCalendarHelp2Wnd
  475. FN SizeHelpWnd
  476.  
  477. END select
  478. END SELECT
  479.  
  480.  
  481. '~'2
  482.  
  483. IF 0 THEN RETURN
  484.  
  485.